<template>
  <div>
    <a-form-model ref="ruleForm" :label-col="labelColBus" :wrapper-col="wrapperCol" :model="form">
      <h3 style="margin-left: 70px">BOX有搭搭配</h3>
      <a-form-model-item label="*  标题">
        {{ form.name }}
      </a-form-model-item>
      <a-form-model-item label="*  介绍" prop="matchAbout">
        {{ form.matchAbout }}
      </a-form-model-item>
      <a-form-model-item label="*  发布人" prop="fashionerId">
        <div v-for="item in fashionerList" :key="item.code">
          <span v-if="item.code === form.fashionerId"> {{ item.name }}</span>
        </div>
      </a-form-model-item>
    </a-form-model>
    <slot name="formItem" :form="form" :labelCol="labelColBus" :wrapperCol="wrapperCol"></slot>
    <slot name="formFooter" :form="form"></slot>
  </div>
</template>
<script>
import { addCondition } from '@api/box/boxLook'
import { matchCreate } from '@api/box/boxLook'
import { mixin } from '../mixin'
export default {
  mixins: [mixin],
  data() {
    return {
      fashionerList: [],
      form: {
        name: '',
        fashionerId: '',
        matchAbout: ''
      },

      matchId: '',
      lookId: ''
    }
  },
  created() {
    this.getCondition()
  },
  methods: {
    getCondition() {
      addCondition()
        .then(res => {
          if (res.code === 0) {
            const { fashioner } = res.data
            this.fashionerList = fashioner
          } else {
            this.$message.error(res.data.msg)
          }
        })
        .catch(err => {})
    },

    submitEvent(info, newLookId) {
      console.log(info)
      const data = {
        requestData: {
          look: {
            sysLookTypesList: info.sysLookType,
            id: newLookId,
            name: this.form.name,
            content: this.form.matchAbout,
            publisherId: this.form.fashionerId
          },
          match: {
            status: info.type,
            isPublish: info.share.isPublish,
            isCreateBill: info.share.isCreateBill,
            otherChannelCanUse: info.share.otherChannelCanUse,
            productList: info.productList.map(e => {
              return {
                productBrand: e.brand,
                productCode: e.name,
                productName: e.value,
                productColorName: e.color_name,
                productColor: e.colorno,
                productId: e.id,
                productImage: e.imgurl
              }
            }),
            lookDiagram: '',
            videoList:
              info.share.videoList && info.share.videoList.length > 0
                ? info.share.videoList.map(e => {
                    return {
                      type: 1,
                      url: e.url,
                      videoImg: e.url + '?vframe/jpg/offset/1'
                    }
                  })
                : [],
            imgList:
              info.share.imgList && info.share.imgList.length > 0
                ? info.share.imgList.map(e => {
                    return {
                      type: 0,
                      url: e.url
                    }
                  })
                : [],
            labelList: [],
            sysLookTypesList: info.sysLookType,
            lookGender: info.share.gender,

            level: info.share.level,
            originSource: info.share.originSource, // 原始来源

            name: this.form.name,
            matchAbout: this.form.matchAbout,
            fashionerId: this.form.fashionerId
          }
        }
      }
      console.log(this.lookId, 'this.lookId')
      console.log(this.matchId, 'this.matchId')

      if (this.matchId) {
        data.requestData.match.id = this.matchId
      }
      console.log(data, '有搭data')

      return matchCreate(data)
        .then(res => {
          if (res.code === 0) {
            this.$message.success('有搭搭配保存成功！')
          } else {
            this.$message.error(res.msg)
          }
        })
        .catch(err => {})
    },
    setData(value) {
      console.log(value, '有搭回显')
      if (value) {
        this.form.name = value.name
        this.form.matchAbout = value.matchAbout
        this.form.fashionerId = value.fashionerId
        this.lookId = value.lookId
        this.matchId = value.id
      }
    }
  }
}
</script>

